// pages/share/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var scene = decodeURIComponent(options.scene);
    if (scene && !options.pid) {
      wx.setStorageSync("pid", scene);
    }
    if (options.pid){
      wx.setStorageSync("pid", options.pid);
    }
    var that = this;
    app.getUserInfo(function (userInfo) {
       that.userInfo = userInfo;
       that.bindPid();
    });
    
  },
  bindPid:function(){
   var pid = wx.getStorageSync("pid");
    if (pid && pid>0){
      app.api("apiv2/user/updatePid", { pid: pid }, function (res) {
        if (res.code != 200) {
          app.alert(res.msg);
        }
        wx.removeStorageSync("pid");
      })
    }
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
   
    return {
      title: '小蜜蜂移动支付全国服务商火热招募中邀您共享千亿市场',
      path: '/pages/share/index?pid=' +this.userInfo.user_id
    }
  },
  backIndex:function(){
   wx.switchTab({
     url: '/pages/index/index',
   })
  },
  createShare:function(){
    
    var page = encodeURIComponent('pages/share/index');
    wx.navigateTo({
      url: '/pages/draw/index?page=' + page + "&scene=" + this.userInfo.user_id,
    })
  }
})